<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="com.lmpop.trade.ti_emaillist.*" %>
<%@page import="com.lmpop.trade.ti_emailaddrs.*" %>
<%@page import="com.lmpop.trade.ti_emailtem.*" %>
<%@page import="com.lmpop.trade.ti_member.*" %>
<%@page import="java.util.*" %>

<html>
  <head>
    
    <title>邮件发送管理</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="/program/plugins/calendar/WdatePicker.js"></script>
<script type="text/javascript" src="/program/admin/sendemail/plugins/thickbox/jquery.js"></script>
<script type="text/javascript" src="/program/admin/sendemail/plugins/thickbox/thickbox.js"></script>
<link rel="stylesheet" href="/program/admin/sendemail/plugins/thickbox/thickbox.css" type="text/css" media="screen" />
<script type="text/javascript" src="/program/admin/sendemail/selectEmailTem.js" ></script>	
<script type="text/javascript" src="/program/admin/sendemail/js_sendmail.js" ></script>	
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_companyInfo.js'></script> 
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_personalInfo.js'></script>   
</head>

<body>

  <% 
  
  	String user_id="",emailAddrs="";
	if( session.getAttribute("session_user_id") != null )
	{
		user_id = session.getAttribute("session_user_id").toString();
	}
	
  	String send_id="";
  	if(request.getParameter("send_id")!=null) send_id = request.getParameter("send_id");
  	Ti_emaillistInfo ti_emaillistInfo = new Ti_emaillistInfo();
	Ti_emailaddrsInfo ti_emailaddrsInfo = new Ti_emailaddrsInfo();
	List emailList = ti_emailaddrsInfo.getEmailListBySendID(send_id);
	
	if(emailList!=null && emailList.size()>0) {
	
	for(int i=0;i<emailList.size();i++){
	  Hashtable emailMap = (Hashtable)emailList.get(i);
	  
	  if(emailMap.get("email")!=null&&emailList.size()-1==i) emailAddrs += emailMap.get("email").toString();
	  else emailAddrs += emailMap.get("email").toString() +"|";
	  }
	
	}

	
	
  	List list = ti_emaillistInfo.getListByPk(send_id);
  	Hashtable map = new Hashtable();
  	if(list!=null && list.size()>0) map = (Hashtable)list.get(0);
  	
  	String cust_id="",send_state="",is_repeat="",title="",content="",pre_date="",send_date="",remark="";
  	if(map.get("cust_id")!=null) cust_id = map.get("cust_id").toString();
  	if(map.get("send_state")!=null) send_state = map.get("send_state").toString();
  	if(map.get("is_repeat")!=null) is_repeat = map.get("is_repeat").toString();
  	if(map.get("title")!=null) title = map.get("title").toString();
  	if(map.get("content")!=null) content = map.get("content").toString();
  	if(map.get("pre_date")!=null) pre_date = map.get("pre_date").toString();
  	if(map.get("send_date")!=null) send_date = map.get("send_date").toString();
  	if(map.get("remark")!=null) remark = map.get("remark").toString();
		Ti_emailtemInfo emailTemInfo = new Ti_emailtemInfo();	
  	//String selectEmailTem = emailTemInfo.getSelectByPara(cust_id,"");
  	
  	/////////////////////////////////////////////////////////////////////以下获取邮件模板
	String s_cust_id="",s_user_id="",s_user_type="";	
	if( session.getAttribute("session_cust_id") != null )
	{
		s_cust_id = session.getAttribute("session_cust_id").toString();
	}
	if( session.getAttribute("session_user_id") != null )
	{
		s_user_id = session.getAttribute("session_user_id").toString();
	}
	if( session.getAttribute("session_user_id") != null )
	{
		s_user_id = session.getAttribute("session_user_id").toString();
	}	
	if( session.getAttribute("session_user_type") != null )
	{
		s_user_type = session.getAttribute("session_user_type").toString();
	}		
	
	Map ti_emailtem = new Hashtable();
	
	//ti_emailtem.put("cust_id",s_cust_id);
	
	String s_tem_name = "";
	if(request.getParameter("search_tem_name")!=null && !request.getParameter("search_tem_name").equals("")){
		//s_tem_name = new String(request.getParameter("search_tem_name").getBytes("utf-8"));
		s_tem_name = request.getParameter("search_tem_name").trim();
		ti_emailtem.put("tem_name",s_tem_name);
	}

	String s_tem_type = "";
	if(request.getParameter("search_tem_type")!=null && !request.getParameter("search_tem_type").equals("")){
		s_tem_type = request.getParameter("search_tem_type").trim();
		ti_emailtem.put("tem_type",s_tem_type);
	}	
	String end_date = "";
	if(request.getParameter("txtEndDate")!=null && !request.getParameter("txtEndDate").equals("")){
		end_date = request.getParameter("txtEndDate").trim();
		ti_emailtem.put("end_date",end_date);
	}	
	String start_date = "";
	if(request.getParameter("txtStartDate")!=null && !request.getParameter("txtStartDate").equals("")){
		start_date = request.getParameter("txtStartDate").trim();
		ti_emailtem.put("start_date",start_date);
	}	
			
	Ti_memberInfo userInfo = new Ti_memberInfo();
	Ti_emailtemInfo ti_emailtemInfo = new Ti_emailtemInfo();
	String iStart = "0";
	int limit = 40;
	if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");
	List emailtemlist = ti_emailtemInfo.getListByPage(ti_emailtem,Integer.parseInt(iStart),limit);
  %>
	
	<h1>修改邮件内容</h1>
	<form action="/doTradeReg.do" method="post" name="addForm">
	<table width="100%" align="center" cellpadding="0" cellspacing="0" class="dl_so">
        <tr>
          <td width="9%" align="center"><img src="/program/admin/index/images/ban_01.gif" /></td>
          <td width="91%" align="left">
		  <h4>关于邮件地址</h4>
		  
		  <span>不同邮箱地址以 | 分隔。</span>
		  </td>
        </tr>
      </table>
      <br/>
	
	
	<table width="100%" class="listtab" cellpadding="1" cellspacing="1" border="0">
		
<input name="send_id" id="send_id" value="<%=send_id%>" type="hidden" />	
<input name="cust_id" id="cust_id" value="<%=cust_id%>"  type="hidden" />
<input name="send_state" id="send_state" value="<%=send_state%>" type="hidden" />
<input name="user_id" id="user_id" value="<%=user_id%>"  type="hidden" />
<input name="end_date" id="end_date" value=""  type="hidden" />
		
		<tr>
			<td align="right" width="15%">
				邮件标题 <font color="red">*</font>
			</td>
			<td><input name="title" id="title" type="text" maxlength="200" value="<%=title%>"  size="24"></td>
		</tr>
		
		<tr>
			<td align="right" width="15%">
				邮箱地址 <font color="red">*</font>
			</td>
			<td>
			<table><tr><td><input name="email" id="email" type="text" value="<%=emailAddrs%>" size="24"/>&nbsp;<span style="color:#666666;">不同邮箱以 | 分隔！</span></td><td>
                <select name="sort1" id="sort1" size="20" style="height:50px;  width:170px" onChange="setSecondsf(this.value);" >
									   <option value = 0>企业会员</option>
									   <option value=1 >个人会员</option>
									</select>
                </td><td>
                <select name="sort2" id="sort2"  size="20" style="width:170px;" onClick="getemail(this.value)" >
										<option value="">请选择...</option>
									</select></div><!-- display:none --></td></tr></table>
			</td>
		</tr>
		<tr>			
			<td align="right" width="15%">
				邮件模板选择: </font>
			</td>
			<td>
				<select name="selectIEmailItems" style="width:100px" id="selectIEmailItems">
				<option value="">请选择..</option>
				
				<% 
				String tem_name ="", tem_id="";
				for(int i =0 ; i!=emailtemlist.size()&&i<limit; i++){
			           Hashtable maps = (Hashtable)emailtemlist.get(i);
			           if(maps.get("tem_name")!=null) tem_name = maps.get("tem_name").toString();
			           if(tem_name.length()> 14) tem_name = tem_name.substring(0,10)+"...";
			           if(maps.get("tem_id")!=null) tem_id = maps.get("tem_id").toString();
			           %><option value="<%=tem_id %>"><%=tem_name %></option><%
				}
				 %>
				</select>
			</td>
		</tr>	
		
		
		<tr>			
			<td align="right" width="15%">
				邮件内容 <font color="red">*</font>
			</td>
			<td>
			<textarea name="content"><%=content%></textarea>
			<script type="text/javascript" src="/program/plugins/ckeditor/ckeditor.js"></script>
			<script type="text/javascript">
				CKEDITOR.replace('content');
			</script>			
			</td>
		</tr>
		
		<tr>
			<td align="right" width="15%">
				预约时间 <font color="red">*</font>
			</td>
			<td>
			 <input name="pre_date" type="text" id="pre_date" class="Wdate" value="<%=pre_date%>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" size="24" />
			 </td>	 
		</tr>

		
		<tr>
			<td align="right" width="15%">
				备注:
			</td>
			<td><input name="remark" id="remark" maxlength="200"  value="<%=remark%>"  type="text"  size="24"/></td>
		</tr>
		
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td align="center">
				<input type="hidden" name="bpm_id" value="9085" />
	  			
				<input type="submit" class="buttoncss" name="tradeSub" onclick="return submitForm()"  value="提交"  />&nbsp;&nbsp;
				<input type="button" class="buttoncss" name="tradeRut" value="返回" onclick="window.location.href='index.jsp';"/>
			</td>
		</tr>
	</table>
	</form>
</body>

</html>
